<?php
/*
 * To change this template, choose Tools | Templates
* and open the template in the editor.
*/
require_once 'lib/raspuns.php';
require_once 'lib/cerere.php';


class Articol
{
	
	var $simbol;
	var $nume;
	var $um;
}

require_once('../conexiune_bazadedate.php');
$cerere = new Cerere(array());

if(isset($cerere->params))
{

	$array_r=$cerere->params;
	$Articol= new Articol();
	
	$Articol->simbol=($array_r->simbol);
	$Articol->nume=($array_r->nume);
	$Articol->um=($array_r->um);
	
	//update
	$query="INSERT INTO articole (simbol,nume,um) VALUES ('$Articol->simbol','$Articol->nume','$Articol->um')";
	$result = mysql_query($query);
	//object response
	$res = new Raspuns();
	$res->success = true;
	$res->message = "Created Record";


	//Need to Send Articol to EXTjs to be correctly viewd in grid
	$result = mysql_query("SELECT * FROM articole where id_articol =".mysql_insert_id());
	$query_array=array();
	$i=0;
	//Iterate all Select
	while($row = mysql_fetch_array($result))
	{
		//Create New Articol instance
		$Articol = new Articol();
		//Fetch Articol Info
		
		$Articol->simbol=$row['simbol'];
		$Articol->nume=$row['nume'];
		$Articol->um=$row['um'];

		//Add Articol to ARRAY
		$query_array[$i]=$Articol;
		$i++;
	}


	$res->data = $query_array;
	//print Json
	print_r($res->to_json());
}
else
{
	//echo "false";
	$res = new Raspuns();
	$res->success = false;
	$res->message = "Error Create record";
	$res->data = array();
	print_r($res->to_json());
}
?>
